﻿using System;
using System.Reflection;
using Castle.ActiveRecord;

namespace WeatherModel
{
    [Serializable]
    [ActiveRecord]
    public abstract class ARBase<T> : ActiveRecordBase<T> where T : ARBase<T>
    {
        public ARBase()
        {
            CreateDate = DateTime.Now;
        }

        [PrimaryKey(PrimaryKeyType.Guid, "`ghsoft_Id`")]
        public Guid Id { get; set; }

        [Property("`CreateDate`", Update = false)]
        public DateTime? CreateDate { get; set; }

        [Property("`ghsoft_Description`")]
        public string Description { get; set; }

        #region Override Equals and GetHashCode

        public override bool Equals(object obj)
        {
            var other = obj as T;
            if (Equals(null, other))
            {
                return false;
            }
            //if ( CheckIdType.IsEmpty( m_IdType, Id ) && CheckIdType.IsEmpty( m_IdType, other.Id ) ) return false;
            if (Id == Guid.Empty && other.Id == Guid.Empty)
            {
                return false;
            }
            return Equals(Id, other.Id);
        }

        public override int GetHashCode()
        {
            //if ( CheckIdType.IsEmpty( m_IdType, Id ) ) return base.GetHashCode();
            if (Id == Guid.Empty)
            {
                return base.GetHashCode();
            }
            return (MethodBase.GetCurrentMethod().DeclaringType.FullName + "#" + Id).GetHashCode();
        }

        #endregion
    }
}
